﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

	<script src="../../js/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
		html, body {
			margin: 0;
			padding: 0;
			border: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
	</style>

</head>
<body>
 	<!--撑满页面-->
	<div class="mini-fit">
		<div id="datagrid1" class="mini-datagrid" showPager="false"
			style="width: 100%; height: 100%;" idField="id" multiSelect="true"
		>
			<div property="columns">
				 <div type="indexcolumn" ></div>
				<div field="version" width="80" headerAlign="center" allowSort="true">版本号</div>
				<div field="userNo" width="120" headerAlign="center" allowSort="true">用户编号</div>
				<div field="userName" width="120" align="center" headerAlign="center">用户名称</div>
				<div field="createTime" width="100" dateFormat="yyyy-MM-dd HH:mm:ss" allowSort="true" >编写时间</div>
				<div field="act" width="100" headerAlign="center" allowSort="false" name="act"
					align="center" renderer="onActionRenderer">操作</div>
			</div>
		</div>

	</div>
<script type="text/javascript">
		mini.parse();
		
		var grid = mini.get("datagrid1");
		grid.setUrl("/document/file/queryFileList.do");
		var fileName = "";
		var userType = '<%= session.getAttribute("userType")%>';
		var userId = '<%= session.getAttribute("userId")%>';
		if(userType == 3) grid.hideColumn("act");
        //渲染按钮
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;
            var loadUrl = "/document/file/download.do?filePath=/upload/"+record.fileName;
            var s = '<a class="New_Button" href="javascript:download(\''+loadUrl+'\')">下载</a>'
            if(userType == 2) {
	            s += ' <a class="Edit_Button" href="javascript:deleteFile(' + record.id + ')" >删除</a>';
	            /* s += ' <a class="Edit_Button" href="javascript:onCheck(' + record.id + ')" >审批</a>'; */
            }
            return s;
        }
		//下载附件
		function download(url) {
			url+= "&fileName="+fileName;
			window.location.href = url;
		}
		function deleteFile(id) {
			if (confirm("确定删除选中记录？")) {
		         grid.loading("操作中，请稍后......");
	             $.ajax({
	                 url: "/document/file/deleteFile.do?id=" +id,
	                 success: function (text) {
	                     grid.reload();
	                 },
	                 error: function () {
	                 }
	             });
	         }
		}
        function SetData(data) {
        	if(data.action == "history") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
				grid.load({docId:data.id,userType:userType,userId:userId});
				fileName = data.name;
        	}
        }
		
		function onCheck(id) {
			mini.open({
				targetWindow : window,
				url : "check.html",
				title : "审批文档",
				width : 600,
				height : 300,
				onload : function() {
					var iframe = this.getIFrameEl();
					var data = {
						action : "check",
						id : id
					};
					iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
					grid.reload();
				}
			});
	}
</script>

</body>
</html>